<%@page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>工程施工排期</title>

<link href='<%=request.getContextPath()%>/js/ux/fullcalendar-1.6.4/fullcalendar/fullcalendar.css' rel='stylesheet' />
<link href='<%=request.getContextPath()%>/js/ux/fullcalendar-1.6.4/fullcalendar/fullcalendar.print.css' rel='stylesheet' media='print' />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery-1.7.2.min.js"></script>

<script type="text/javascript" src="<%=request.getContextPath()%>/js/ux/fullcalendar-1.6.4/lib/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/ux/fullcalendar-1.6.4/fullcalendar/fullcalendar.min.js"></script>

<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/js/jquery/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/js/jquery/themes/icon.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/js/jquery/demo/demo.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
Date.prototype.pattern = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
</script>
<script type='text/javascript'>
<!--
			var allProjects  = new Array();
			var hostname = location.hostname;
			/*dayclick绑定的函数*/
			function showCurrentDayProjects(date,calendar){
				
			}
			
			
			Array.prototype.delRepeat=function(){
				var newArray=new Array();
				var len=this.length;
				for (var i=0;i<len ;i++){
					for(var j=i+1;j<len;j++){
						if(this[i].id===this[j].id){
							j=++i;
						}
					}
					newArray.push(this[i]);
				}
				return newArray;
			}


		$(document).ready(function() {
			var date = new Date();
			var d = date.getDate();
			var m = date.getMonth();
			var y = date.getFullYear();
			// var d = new Date();
			$("#selecteddate").attr("value",date.pattern("yyyy-MM"));
			
			var calendar  = $('#calendar').fullCalendar({
				theme: false,
			 	header: {   
			 		left: 'prev,next today',
					center: 'title',
					right: 'month,agendaWeek,agendaDay'
	            },   
	           
		        monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	            monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	            dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
	            dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
	            today: ["今天"],
	            firstDay: 1,
	            buttonText: {
		          today: '本月',
				  month: '月',
				  week: '周',
				  day: '日',
				  prev: '上一月',
				  next: '下一月'
		      	},
				selectable: true,
				currentTimezone: 'Asia/Beijing',
				eventClick: function(event) {
				},
				eventMouseover:function(event){
				},
				eventMouseout:function(event){
					
				},
	            dayClick: function(date, allDay, jsEvent, view ){
	               showCurrentDayProjects(date,this);
	            },
	            selectable: true,   
	            selectHelper: true,   
	            select: function(start, end, allDay) {   
	            	$.messager.prompt("工作安排","请输入您的工作内容",function(val){
						 calendar.fullCalendar('renderEvent',   
		                          {   
		                               title: val,   
		                               start: start,   
		                               end: end,
		                               allDay: allDay     
		                           },   
		                           true // make the event "stick"   
		                       );//把刚输入的日程计划在页面上进行显示   
						 calendar.fullCalendar('unselect');          
					});
 
	            },   
	             editable: true,   
	             //events:'/tiantian/schedule/containEvents'   
	             events:[{
	            	 title: '测试数据',
					 start: new Date(y, m, d)
	             },{
	            	 title: 'Long Event',
					 start: new Date(y, m, d+5),
					 end: new Date(y, m, d+2)
	             }]//表示初始化时的数据，这里是空的，等前面的ajax请求返回后就会有新的数据在页面显示   
				
			});		
			// 重新注册 左上角三个按钮 ： 功能按钮
			jQuery('.fc-button-prev').unbind('click');
			jQuery('.fc-button-next').unbind('click');
	
			jQuery('.fc-button-prev').bind('click', fnMthChange);
			jQuery('.fc-button-next').bind('click', fnMthChange);
			jQuery('.fc-button-today').bind('click', fnMthChange);
			function fnMthChange() {
				changeTime(this.innerText);
				if (jQuery('#calendar').fullCalendar('getView').name == "month") {
					showTime();
				}
			}
			
			
			function perMonth(){
				var date = $("#selecteddate").attr("value",date);
				var year  = date.split("-")[0];
				var month = date.split("-")[1];
				if(month >1 ){
					month = month -1
					$("#selecteddate").attr("value",year +"-" +month)
				}else{
					year = year - 1 
					month = 12;
					$("#selecteddate").attr("value",year +"-" +month)
				}
			}
			
			function nextMonth(){
				var date = $("#selecteddate").attr("value",date)
				var year  = date.split("-")[0];
				var month = date.split("-")[1];
				if(month <12 ){
					month = Number(month) + 1
					$("#selecteddate").attr("value",year +"-" +month)
				}else{
					year = Number(year) + 1 
					month = 1;
					$("#selecteddate").attr("value",year +"-" +month)
				}
			}
			
			function thisMyMonth(){
				var d = new Date();
				// alert("今天星期"+"天一二三四五六".charAt(new Date(d).getDay()));
				$("#selecteddate").attr("value",d.pattern("yyyy-MM"));
			}
			function changeTime(label) {
				if (jQuery.trim(label) == "上一月") {
					jQuery('#calendar').fullCalendar('prev');
					perMonth();
				} else if (jQuery.trim(label) == "下一月") {
					jQuery('#calendar').fullCalendar('next');
					nextMonth();
				} else if (jQuery.trim(label) == "本月") {
					jQuery('#calendar').fullCalendar('today');
					thisMyMonth();
				}
			}
			// showTime();
		});
	
		
		function showTime() {
			var view = jQuery('#calendar').fullCalendar('getView');
			var start = toStrDateTime(view.start); // view.calendar.formatDate(view.start,
													// 'u2');
			var end = toStrDateTime(view.end);// view.calendar.formatDate(view.end,
												// 'u2');
			// 查询
			   var viewStart = $.fullCalendar.formatDate(view.start,"yyyy-MM-dd");   
                   var viewviewName = view.name;   
                   var onlyshowMe  =  $("#onlyMeTask").attr("checked");
                   //alert(viewStart+viewName);   
                   //alert(viewStart);
                   var datetime = new Date().getTime();
                  $("#calendar").fullCalendar('removeEvents');   
                
	                for(var i=  allProjects.length -1 ;i>0 ;i--){
	                	allProjects.pop();
	                }
                  $.getJSON('xxxurl',{onlyMeTask:onlyshowMe,underYear:'2011',underMonth:'12',start:viewStart,datetime:datetime},function(data) {   
                	  
                	   var j = 0;
                	   $("#fullmonthprojects").empty();
                       for(var i=0;i<data.length;i++) {   
                       
	                       if(data[i].fullMoon == 1 ){
								$("#fullmonthprojects").append("<li><span class='first'>"+(++j)+")</span><span  class='second'>"+data[i].projectName+"</span><span  class='third'><a href='xxxurl?id="+data[i].id+"'>详情</a></span></li>");
								continue;
							}
                       	   allProjects.push(data[i])
                           //alert(data[i].id);   
                           var obj = new Object();   
                           obj.id = data[i].id;   
                           obj.title = data[i].shortName;   
                           obj.projectName = data[i].projectName;
                           //obj.allDay = data[i].allDay;   
                           obj.start = new Date(data[i].startDateLong) //$.fullCalendar.parseDate(data[i].startDateLong/1000);   
                           obj.end = new Date(data[i].endDateLong)//$.fullCalendar.parseDate(data[i].end/1000);   
                           obj.backgroundColor = data[i].projectColor;
                           obj.location  =  data[i].meetingAddress;
                           //alert(data[i].start);   
                           //alert(obj.start);   
                           //alert($.fullCalendar.formatDate(obj.start,"yyyy-MM-dd HH:mm:ss"));   
                           $("#calendar").fullCalendar('renderEvent',obj,true);//把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示   
                       }   
                   });   
		}
	function toStrDateTime(object) {
		var view = jQuery('#calendar').fullCalendar('getView');
		var str = view.calendar.formatDate(object, 'u');
	
		str = str.replace("T", " ");
		str = str.replace("Z", "");
		return str;
	}
	
	
	function closeEventInfo()
	{
		$("#eventInfo").css("display","none");
	}
	
	function gotoDate(){
		var selectdstr =    $("#selecteddate").val();   
     	var selectdate = $.fullCalendar.parseDate(selectdstr, "yyyy-mm-dd");   
     	$('#calendar').fullCalendar( 'gotoDate', selectdate.getFullYear(), selectdate.getMonth(), selectdate.getDate());  
	}
</script>

</head>
<body>
<div id='calendar'> </div> 
</body>
</html>